<?php
namespace app\admin\model;
use think\Model;
use think\Db;
class User extends Model
{
    function userData($size=15,$where=''){
        $map[] = ['is_del','=','0'];
        if(input('user_name') && input('user_name')<>''){
            $map[] = ['user_name','like','%'.input('user_name').'%'];
        }
        if(input('nick_name') && input('nick_name')<>''){
            $map[] = ['nick_name','like','%'.input('nick_name').'%'];
        }
        if($where <> ''){
            $map = array_merge($where,$map);
        }
        $count = Db::name('user')->where($map)->count();// 查询满足要求的总记录数
        $list = Db::name('user')
//            ->join('subject s','e.subjectid = s.subjectid','left')
//            ->field('e.*,s.subject_name')
            ->where($map)
            ->order('userid desc')
            ->paginate($size,$count,['query'=>request()->param()])
            ->each(function($item,$key){
                return $item;
            });
        $page = $list->render();

        $data['count'] = $count;
        $data['list'] = $list;
        $data['page'] = $page;
        return $data;
    }

    //处理参数
    function disposeData($data,$act=''){
        $newData['art_type'] = $data['art_type'];
        $newData['user_name'] = $data['user_name'];
        $newData['pwd'] = $data['password'];
        $newData['password'] = encrypt($data['password']);
        $newData['nick_name'] = $data['nick_name'];
        $newData['sex'] = $data['sex'];
        if($data['userid']>0){
        }else{
            $newData['add_time'] = time();
        }

        return $newData;
    }

}